package com.xiaoshuidi.cloud.module.member.controller.app.feedback;


import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.framework.security.core.util.SecurityFrameworkUtils;
import com.xiaoshuidi.cloud.module.member.controller.app.feedback.vo.HistoricalFeedbackReqVO;
import com.xiaoshuidi.cloud.module.member.controller.app.feedback.vo.HistoricalFeedbackRespVO;
import com.xiaoshuidi.cloud.module.member.controller.app.feedback.vo.MemberFeedbackCreateReqVO;
import com.xiaoshuidi.cloud.module.member.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.member.service.feedback.MemberFeedbackService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;
import static com.xiaoshuidi.cloud.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Slf4j
@Tag(name = "租客端 - 意见反馈")
@RestController
@RequestMapping(ApiConstants.NAME + "/member-feedback")
@RequiredArgsConstructor
public class AppMemberFeedbackController {

    private final MemberFeedbackService memberFeedbackService;

    @PostMapping("/create")
    @Operation(summary = "创建意见反馈")
    public CommonResult<Long> create(@Valid @RequestBody MemberFeedbackCreateReqVO createReqVO){
        Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
        return success(memberFeedbackService.create(loginUserId, createReqVO));
    }

    @Operation(summary = "查看历史反馈")
    @GetMapping("/historical-feedback")
    public CommonResult<PageResult<HistoricalFeedbackRespVO>> historicalFeedback(HistoricalFeedbackReqVO historicalFeedbackReqVO){
        return success(memberFeedbackService.historicalFeedback(getLoginUserId(), historicalFeedbackReqVO));
    }
}
